
package com.primeton.eos.oss.model.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.eos.system.utility.PageResultList;

import com.eos.data.datacontext.DataContextManager;
import com.eos.data.datacontext.IMUODataContext;

import com.primeton.eos.oss.model.dao.CrecAccountDao;
import com.primeton.eos.oss.model.newdataset.CrecAccount;

@Service
public class CrecAccountService {

    @Autowired
    private CrecAccountDao crecAccountDao;


    public PageResultList<CrecAccount> queryCrecAccountsWithPage(String username,  int pageSize, int pageIndex) {
        //TODO 记录日志
        return crecAccountDao.queryCrecAccountsWithPage(username,  pageSize, pageIndex);
    }

    public CrecAccount getCrecAccountById(String id) {
        //TODO 记录日志
        return crecAccountDao.getEntity(CrecAccount.QNAME, id);
    }

    @Transactional
    public void createCrecAccount(CrecAccount crecAccount) {
        //TODO 记录日志
    	String userName = "";
		IMUODataContext muo = DataContextManager.current().getMUODataContext();
		if (muo != null) {
			userName = muo.getUserObject().getUserName();
		}
        crecAccount.set("createUser", userName);
        crecAccount.set("createTime", new Date());
        crecAccount.set("updateUser", userName);
        crecAccount.set("updateTime", new Date());

        crecAccountDao.getPrimaryKey(crecAccount);
        crecAccountDao.insertEntity(crecAccount);
    }
    
    @Transactional
    public void modifyCrecAccount(CrecAccount crecAccount) {
        //TODO 记录日志
     	String userName = "";
		IMUODataContext muo = DataContextManager.current().getMUODataContext();
		if (muo != null) {
			userName = muo.getUserObject().getUserName();
		}
        crecAccount.set("updateUser", userName);
        crecAccount.set("updateTime", new Date());
 
        crecAccountDao.updateEntity(crecAccount);
    }
    
     @Transactional
    public void removeCrecAccount(CrecAccount[] crecAccount) {
        //TODO 记录日志
        crecAccountDao.deleteEntity(crecAccount);
    }

}





